package com.china08.yxyapi.api.manage.stu.mystudy.weikecheng;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.api.YxyApiBaseController;
import com.china08.yxyapi.model.YxyApiRespModel;
import com.china08.yxyapi.repository.mg.YxyUserFavorRepository;

/**
 * 学生 -- 微课中心-- 我的收藏 取消收藏
 * 
 */
@CrossOrigin
@RestController("StuStudyWeikechengDelControlle")
public class StudyWeikechengDelController extends YxyApiBaseController {

    @Autowired
    private YxyUserFavorRepository favorRepository;

    @RequestMapping(value = "/api_yw/manage/stu/mystudy/weikecheng", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public Object precess(HttpServletRequest request, HttpServletResponse response,
            @RequestParam(value = "weikeId", required = true) String weikeId, RespModel respModel) {
        String userId = getProfile(request, response).getId();
        // String schoolId = getProfile(request, response).getSchoolId();
        // String roleId = getProfile(request, response).getRoleId();
        // // 用户的角色 使用云校接口
        // String url = YX_API_PATH + "/comm/user/role/" + userId + "/" + roleId
        // + "/" + schoolId;
        // RestTemplate rt = new RestTemplate();
        // String userRoleId = rt.getForObject(url, String.class);
        // favorRepository.deleteByResIdAndUserIdAndUserRoleId(weikeId, userId,
        // userRoleId);
        favorRepository.deleteByResIdAndUserId(weikeId, userId);
        respModel = new RespModel();
        respModel.setMessage("取消收藏成功");
        return respModel;
    }

    protected static class RespModel extends YxyApiRespModel {

    }
}